<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta charset="utf-8">
	<title></title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
	<meta name="description" content="">
	<meta name="author" content="">
	<!-- STYLESHEETS -->
	<!--[if lt IE 9]><script src="../../js/flot/excanvas.min.js"></script><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
	<link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
	<link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
	<link rel="stylesheet" type="text/css" href="../../css/responsive.css">

	<link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
	<!-- file-input -->
	<link rel="stylesheet" type="text/css" href="../../js/file-input/fileinput.css" />
	<!-- SELECT2 -->
	<link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />
	<!-- UNIFORM -->
	<link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css" />
	<!-- datatable -->
	<link rel="stylesheet" href="../../js/datatables/datatable.css">
	<!-- WIZARD -->
	<link rel="stylesheet" type="text/css" href="../../js/bootstrap-wizard/wizard.css" />
	<link rel="stylesheet" href="../../js/datepicker/datepicker.css">
	<!-- FONTS 
	<link href='http://fonts.useso.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
-->
	<!-- JQUERY -->
	<script src="../../js/jquery/jquery-2.0.3.min.js"></script>
	<script language="javascript" type="text/javascript" src="../../js/My97DatePicker/WdatePicker.js"></script>
	<script src="../../js/common.js"></script>
</head>

<body>
	<header class="navbar clearfix" id="header">
	</header>

	<!-- PAGE -->
	<section id="page">
		<!-- SIDEBAR -->
		<div id="sidebar" class="sidebar">
			<div class="sidebar-menu nav-collapse">
				<!-- SIDEBAR MENU -->
				<ul>
				</ul>
				<!-- /SIDEBAR MENU -->
			</div>
		</div>
		<!-- /SIDEBAR -->
		<div id="main-content">
			<div class="container">
				<div class="row">
					<div id="content" class="col-lg-12">
						<!-- PAGE HEADER-->
						<div class="row">
							<div class="col-sm-12">
								<div class="page-header">
									<!-- STYLER -->

									<!-- /STYLER -->
									<!-- BREADCRUMBS -->
									<ul class="breadcrumb">
										<li>
											<i class="fa fa-home"></i>
											<a href="index.html">首页</a>
										</li>
										<li>
											<a href="#">商品管理</a>
										</li>
										<li>维护商品</li>
									</ul>
									<!-- /BREADCRUMBS -->

								</div>
							</div>
						</div>
						<!-- /PAGE HEADER -->
						<!-- SAMPLE -->
						<form id="form_pack">
							<div class="row col-md-12">
								<div class="box border primary" style="margin-left: 20px;">
									<div class="box-title">
										<h4>
											<i class="fa fa-bars"></i>拼团设置</h4>
									</div>
									<div class="box-body big" style="padding:10px;height:auto">
										<div class="row" style="margin-top:10px;">
											<label class="control-label col-md-3">
												<span class="required">*</span>团购名称：</label>
											<div class="col-md-5 inline">
												<input type="text" class="form-control" name="tuanName" placeholder="请输入团购名称" maxlength="50" />
												<input type="hidden" name="id" />
												<span class="error-span"></span>
											</div>
										</div>
										<div class="row" style="margin-top:10px;">
											<label class="control-label col-md-3">
												<span class="required">*</span>团购描述：</label>
											<div class="col-md-5 inline">
												<input type="text" class="form-control" name="tuanDesc" placeholder="请输入团购" maxlength="150" />

												<span class="error-span"></span>
											</div>
										</div>
										<div class="row" style="margin-top:10px;height:90px">
											<label class="control-label col-md-3">
												<span class="required">*</span>团购图片：</label>
											<div class="col-md-5 inline">
												<form>
													<div class="col-md-8">
														<div hidden-image></div>
														<div class="fileinput fileinput-new" data-provides="fileinput">
															<div class="image_preview_list" style="float:left;" id="imgs">
																<div class="fileinput-preview thumbnail image_preview_default" data-trigger="fileinput" style="width: 120px; height: 90px;"></div>
															</div>
															<div style="float:left; margin-left:5px; padding-top:23px;" class="addnewimg" id="f_span">
																<span class="btn btn-default btn-file" id="fir">
																	<span class="fileinput-new" id="two">上传图片</span>
																	<span class="fileinput-exists">Change</span>
																	<input type="file" name="uploadFile" upload-file="imageUrlProduct">
																</span>
																<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" style=" margin-bottom: 0px;margin-top:10px;">
																	<div class="progress-bar progress-bar-success" style="width:0%;"></div>
																</div>
															</div>

														</div>


													</div>
												</form>

												<span class="error-span"></span>
											</div>
										</div>
										<div class="row" style="margin-top:10px">
											<label class="control-label col-md-3">
												<span class="required">*</span>拼团模式：</label>
											<div class="col-md-4">
												<select id="groupMode_select" name="groupMode">
													<option></option>
													<option value="Ordinary">普通拼团</option>
													<option value="OnlyNew">新客团</option>
													<option value="OldBeltNew">老带新</option>
												</select>
												<span class="error-span"></span>
											</div>

										</div>
										<div class="row" style="margin-top:10px">
											<label class="control-label col-md-3">拼团属性：</label>
											<div class="col-md-4">
												<div id="attribute_check" class="checkbox-custom checkbox-default">
													
												</div>
												<span class="error-span"></span>
											</div>
										</div>
										<div class="row" style="margin-top:10px;">
											<label class="control-label col-md-3">
												<span class="required">*</span>数量：</label>
											<div class="col-md-5 inline">
												<input type="text" class="form-control" name="amount" placeholder="请输入几件团" maxlength="50" />

												<span class="error-span"></span>
											</div>
										</div>
										<div class="row" style="margin-top:10px;">
											<label class="control-label col-md-3">
												<span class="required">*</span>团购价：</label>
											<div class="col-md-5 inline">
												<input type="text" class="form-control" name="tuanPrice" placeholder="请输入团购价" maxlength="50" />

												<span class="error-span"></span>
											</div>
										</div>
										<div class="row" style="margin-top:10px;">
											<label class="control-label col-md-3">
												<span class="required">*</span>原价：</label>
											<div class="col-md-5 inline">
												<input type="text" class="form-control" name="tuanOriginalPrice" placeholder="请输入原价" maxlength="50" />

												<span class="error-span"></span>
											</div>
										</div>

										<div class="row" style="margin-top:10px;">
											<label class="control-label col-md-3">
												<span class="required">*</span>链接地址：</label>
											<div class="col-md-5 inline">
												<input type="text" class="form-control" name="tuanLinkUrl" placeholder="请输入地址" maxlength="200" />

												<span class="error-span"></span>
											</div>
										</div>
										<div class="row" id="rangDate" style="margin-top:10px;">
											<label class="control-label col-md-3">
												<span class="required">*</span>生效日期：</label>
											<div class="col-md-6 inline" style="display:inline-flex">
												<input class="Wdate" style="height:34px" type="text" id="d4311" name="startDate" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'d4312\')||\'2030-10-01\'}',dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false,readOnly:true})"> -
												<input class="Wdate" type="text" style="height:34px" id="d4312" name="endDate" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'d4311\')}',maxDate:'2030-10-01',dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false,readOnly:true})">
												<span class="error-span"></span>
											</div>
										</div>
									</div>
								</div>
							</div>
						</form>
						<div class="row" style="height: 30px;">
							<div class="col-md-12" style="text-align: center;">
								<div class="box ">
									<a href="#" class="btn btn-success config bt-submit" style="width: 100px">
										保存
									</a>
								</div>
							</div>
						</div>
					</div>
				</div>


				<!-- /SAMPLE -->

				<div class="footer-tools">
					<span class="go-top">
						<i class="fa fa-chevron-up"></i> Top
					</span>
				</div>
			</div>
			<!-- /CONTENT-->
		</div>
		</div>
		</div>
	</section>
	<!--/PAGE -->
	<!-- JAVASCRIPTS -->
	<!-- Placed at the end of the document so the pages load faster -->
	<!-- JQUERY UI-->
	<script src="../../js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js"></script>
	<!-- BOOTSTRAP -->
	<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>

	<!-- BLOCK UI -->
	<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>

	<!-- AUTOSIZE -->
	<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>

	<!-- INPUT MASK -->
	<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>
	<!-- SELECT2 -->
	<script type="text/javascript" src="../../js/select2/select2.min.js"></script>

	<!-- bootstrap-fileupload -->
	<script type="text/javascript" src="../../js/jquery-upload/js/jquery.iframe-transport.js"></script>
	<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload.min.js"></script>
	<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-process.min.js"></script>
	<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-validate.min.js"></script>

	<!-- UNIFORM -->
	<script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>
	<!-- spinner -->
	<script src="../../js/spinner/spin.js"></script>
	<script src="../../js/jquery-validate/jquery.validate.min.js"></script>
	<!--bootbox-->
	<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
	<!-- COOKIE -->
	<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
	<!-- CUSTOM SCRIPT -->
	<script src="../../js/script.js"></script>

	<script>
		var AddProductSecond = function () {
			var wizform = $('#form_pack');
			var selectProducts = [];//参与活动的商品
			var id = null, flag;
			var $mainDataTable = null;
			var formValiInit = function () {
				wizform.validate({
					doNotHideMessage: true,
					errorClass: 'error-span',
					errorElement: 'span',
					rules: {
						tuanName: { required: true },
						tuanDesc: { required: true },
						startDate: { required: true },
						endDate: { required: true },
						amount: { required: true },
						groupMode: { required: true },
						tuanPrice: { required: true },
						tuanOriginalPrice: { required: true },
						tuanLinkUrl: { required: true }
					},
					highlight: function (element) {
						$(element)
							.closest('.form-group').removeClass('has-success').addClass('has-error');
					},

					unhighlight: function (element) {
						$(element)
							.closest('.form-group').removeClass('has-error');
					},
					success: function (label) {
						label.addClass('valid')
							.closest('.form-group').removeClass('has-error').addClass('has-success');

					}
				});
			};

			var saveProductTuan = function () {
				if (wizform.valid() == false) return false;
				var tuan = $("#form_pack").serializeObject();
				$.blockUI();
				var url = App.getContextPath() + "admin/tuan/addProductTuan.do";
				if (id != null)
					url = App.getContextPath() + "admin/tuan/updateTuan.do";
				tuan.startDate = null;
				tuan.endDate = null;
				tuan.attribute = tuan.attribute.toString();
				$.ajax({
					type: "post",
					url: url,
					data: { tuan: JSON.stringify(tuan), startDate: $("[name=startDate]").val(), endDate: $("[name=endDate]").val() },
					async: true,
					success: function (result) {
						$.unblockUI();
						if (result.type == "error") {
							$.alert(result.extra);

						} else {
							location.href = "producttuan.html";
						}
					}
				});
			};
			var fileUpLoad = function () {
				$(".progress").hide();
				$("[upload-file=imageUrlProduct]").fileupload({
					url: App.getContextPath() + "admin/file/uploadFile.do",
					formData: { fileType: "Temp" },
					dataType: 'json',
					acceptFileTypes: /(\.|\/)(gif|jpe?g|png|JPG?g)$/i,
					iframe: true,
					start: function (e) {
						$('.progress').fadeIn(300);
						return true;
					},
					autoUpload: true,
					done: function (e, data) {
						var result = data.result;
						if (result.message != "") {
							$.alert(result.message);
							return false;
						} else {

							var $tr = $(this).closest("form");
							$tr.find("[hidden-image]").append("<input type='hidden' name='tuanImagePath' value='" + result.fileUrl + "' />");
							$tr.find(".image_preview_default").html("<img src='" + result.fileUrl + "' />");
						}
					},
					progressall: function (e, data) {
						var progress = parseInt(data.loaded / data.total * 100, 10);
						$('.progress .progress-bar').css('width', progress + '%');
					}
				}).on('fileuploaddone', function (e, data) {
					$(".progress").fadeOut(300);

				});

			};
			//获取活动详情
			var getProductTuan = function (id) {
				$.ajax({
					type: "post",
					url: App.getContextPath() + "admin/tuan/getTuan.do",
					data: { id: id },
					async: true,
					success: function (result) {
						$("[name=id]").val(result.id);
						$("[name=tuanName]").val(result.tuanName);
						$("[name=tuanDesc]").val(result.tuanDesc);
						$("[name=startDate]").val(new Date(parseInt(result.startDate)).format("yyyy-MM-dd hh:mm:ss"));
						$("[name=endDate]").val(new Date(parseInt(result.endDate)).format("yyyy-MM-dd hh:mm:ss"));
						$("[name=tuanPrice]").val(result.tuanPrice);
						$("[name=amount]").val(result.amount);
						$("#groupMode_select").select2("val", result.groupMode);
						$("[name=tuanOriginalPrice]").val(result.tuanOriginalPrice);
						$("[name=tuanLinkUrl]").val(result.tuanLinkUrl);
						$(".image_preview_default").html("<img src='" + result.tuanImagePath + "' />");
						if (result.attribute && result.attribute) {
							var arr = result.attribute.split(',');
							$(arr).each(function(index, item){
								$("[name=attribute]").each(function(){
									if ($(this).val() === item) {
										$(this).prop('checked', true);
									}
								});
							});
						}

					}
				});
			};
			var getAttribute = function(id) {
				$.ajax({
					type: "get",
					url: App.getContextPath() + "admin/attribute/findAttributeByParentId.do",
					data: { parentId: id },
					async: false,
					success: function (result) {
						if (result.type == "success") {
							$(result.extra).each(function(index, item){
								$("#attribute_check").append('<input type="checkbox" id="attribute'+index+'" name="attribute" value="'+item.attributeName+'"/>&nbsp;<label style="font-weight:normal;" for="attribute'+index+'">'+item.attributeName+'</label>&nbsp;&nbsp;');
							});
						}

					}
				});
			}

			return {
				init: function () {
					App.init();
					formValiInit();
					fileUpLoad();
					getAttribute(16);
					var date = new Date();
					$("[name=startTime]").val(date.format("yyyy-MM-dd hh:mm"));
					$("[name=endTime]").val(date.format("yyyy-MM-dd hh:mm"));

					$(".bt-submit").click(saveProductTuan);
					flag = $.getUrlParam("flag");
					id = $.getUrlParam("id");
					if (id != null) { getProductTuan(id); }
					$("#groupMode_select").select2({ placeholder: "选择拼团模式" });

				}
			}
		}();
		$(function () {
			$("#header").load("../head.html");
			AddProductSecond.init();
		});
	</script>

	<!-- /JAVASCRIPTS -->
</body>

</html>